package com.hue.concurrent.day01;

/*
    打断标记的使用:
        正常运行的线程被打断之后打断标记会被置为true
        处于sleep、wait、join等方法在阻塞时被打断，打断标记不会被修改
 */
public class Demo10 {
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            while (true) {
                //t1正常运行时被打断，标记被置为true
                if (Thread.currentThread().isInterrupted()) {
                    System.out.println("t1被打断后退出");
                    break;
                }
            }
        }, "t1");
        t1.start();

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("t1被打断...");
        t1.interrupt();
    }
}
